package app.view.module
{
	import com.gaiaframework.api.IStyleSheet;
	import com.gaiaframework.debug.GaiaDebug;
	import com.gaiaframework.templates.AbstractPage;
	
	import flash.events.Event;
	import flash.text.AntiAliasType;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	public class BaseGaiaPage extends AbstractPage
	{
		
		public var css:IStyleSheet;
		
		public function BaseGaiaPage()
		{
			super();
			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true);
		}
		
		//override in page
		protected function onAddedToStage(e:Event):void
		{
			GaiaDebug.log("BasePage.onAddedToStage");
			removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
			stage.addEventListener(Event.RESIZE, onResize, false, 0, true);
			configUI();
			addListeners();
			draw();
			onResize();
		}
		
		//override in page
		protected function configUI():void
		{
			//1-time property setting
			//set visibility
			//add children
			//set stage elements to variables
			//get textFormats from css
			//initialize stuff
			//throw new Error('override this function');
			
		}
		//override in page
		protected function addListeners():void
		{
			//add event listeners to page ui elements
			//throw new Error('override this function');
		}
		//override in page
		protected function draw():void
		{
			//repeatable property setting
			//throw new Error('override this function');

		}
		//override in page
		protected function onResize(event:Event = null):void
		{
			//stuff to do everytime the stage resizes
			//throw new Error('override this function');
		}
		//override in page
		public function removeAll():void
		{
			//remove event listeners
			//null stuff out that will be rebuilt next time added to stage
			//throw new Error('override this function');
		}
		
		private function radianToDegree( num:Number ) : Number
		{
			return num * 180 / Math.PI;
		}
		
		public function formatText(field:*, text:String, format:TextFormat, autoSize:String = "left", selectable:Boolean=false, thickness:int = 0, sharpness:int = 0, letterSpacing:Number = 0):void
		{
			
			var tf:TextFormat = field.getTextFormat();
			tf.font = format.font;
			tf.color = format.color;
			tf.size = format.size;
			tf.bold = format.bold;
			tf.italic = format.italic;
			tf.underline = format.underline;
			tf.letterSpacing = letterSpacing;
			
			field.embedFonts = true;
			field.antiAliasType = AntiAliasType.ADVANCED;
			field.thickness = thickness;
			field.sharpness = sharpness;
			field.autoSize = autoSize;
			field.selectable = selectable;
			field.defaultTextFormat = tf;//<< sets format for any text added after setTextFormat is is applied
			field.htmlText = (text) ? text : '';
			field.setTextFormat(tf); //<< sets format of text currently in field, overwrites any html currently in field, i.e. <br/> tags in xml - (use carraige return in xml for line breaks)
			
			
		}
		
		protected function setStyleSheet():void
		{
			css = IStyleSheet(assets.css);
		}
		
		
		
	}
}